package com.leyou.order.web;

import com.leyou.order.dto.OrderDTO;
import com.leyou.order.service.OrderService;
import com.leyou.order.vo.OrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * Created by IntelliJ IDEA.
 *
 * @author: wangzibeng
 * Date: 2019/5/20 0020
 * Time: 10:23
 */

@RestController
@RequestMapping("order")
public class OrderController {
    @Autowired
    private OrderService orderService;


    @PostMapping
    public ResponseEntity<Long> createOrder(@RequestBody @Valid OrderDTO orderDTO) {
        return ResponseEntity.status(HttpStatus.CREATED).body(orderService.createOrder(orderDTO));
    }

    @GetMapping("{orderId}")
    public ResponseEntity<OrderVO> queryOrderById(@PathVariable("orderId") Long orderId) {
        return ResponseEntity.ok(orderService.queryOrderById(orderId));
    }
}
